def main():
    # 字符串主要三个问题：一个修改，一个查询，一个输出
    # use_replace()
    # use_split()
    # use_join()
    # use_strip()
    use_letter()


# 1.字符替换
def use_replace():
    s = "你知道框架是什么吗？你知道理解是什么吗？你知道练习是什么吗"
    replace = s.replace("什么", "重要")
    print(replace)

    s0 = "\t我喜欢框架\t我喜欢理解"
    expandtabs = s0.expandtabs(8)
    print(expandtabs)

    maketrans = str.maketrans("123", "234", "5")
    s1 = "1243456"
    translate = s1.translate(maketrans)
    print(translate)


# 2.字符分割
def use_split():
    # split的操作
    s1 = "如果没有框架那是扯蛋，没有理解那是无意义，没有练习那就不需要去花时间"
    split = s1.split("没有", maxsplit=1)
    print(split)
    rsplit = s1.rsplit("没有", maxsplit=1)
    print(rsplit)
    s2 = "我喜欢框架\n框架喜欢你\n你喜欢去一个地方"
    splitlines = s2.splitlines()  # 只换换行符
    print(splitlines)
    # partition的操作
    s: str = "我爱一个框架，你爱一个理解，最后有了实践"
    p1 = s.partition("一个")
    p2 = s.rpartition("一个")
    print(p1)
    print(p2)
    p3 = s.partition("没有")
    p4 = s.rpartition("没有")
    print(type(p3))
    print(p4)


# 3.字符拼接
def use_join():
    l = ["我喜欢小平", "小平喜欢小红", "小红喜欢小明"]
    s = "-".join(l)
    print(s)


# 4.字符修剪与填充
def use_strip():
    # 修剪
    s = "   框架理解练习   \n "
    strip = s.strip("理习 \n")
    print(strip)
    # 填充
    s1 = "框架理解练习"
    s1 = s1.center(9,"好")
    print(s1)


def use_letter():
    s = "framework comprehend exercise"
    s1 = s.upper()
    s2 = s.title()
    s3 = s.swapcase()
    s4 = s.capitalize()
    print(s4)


if __name__ == '__main__':
    main()
